package edu.sias.dao;

import edu.sias.pojo.Category;
import edu.sias.util.DButil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

//关于文章类别操作的数据层
public class CategoryDao {

    //查询所有的文章类别
    public List<Category> getCategory() throws SQLException {
        String sql =
                "select * from category";
        ArrayList<Category> list
                = new ArrayList<>();
        //执行sql
        ResultSet rs
                = DButil.select(sql, new Object[]{});
        //遍历数据
        while (rs.next()){
            int id = rs.getInt("id");
            String name = rs.getString("name");
            String desc = rs.getString("desc");
            Category category
                    = new Category(id,name,desc);
            list.add(category);
        }
        return list;

    }



}
